package com.example.projectdemo.materialComponents;

import android.os.Bundle;
import android.view.View;

import com.bumptech.glide.Glide;
import com.example.projectdemo.R;
import com.google.android.material.imageview.ShapeableImageView;
import com.google.android.material.shape.AbsoluteCornerSize;
import com.google.android.material.shape.CornerFamily;
import com.google.android.material.shape.RelativeCornerSize;
import com.google.android.material.shape.ShapeAppearanceModel;

import androidx.appcompat.app.AppCompatActivity;

public class ShapeableImageViewActivity extends AppCompatActivity {

    private ShapeableImageView logo;
    private ShapeAppearanceModel appearanceModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shapeable_image_view);

        logo = findViewById(R.id.logo);
        //代码接收一个ShapeAppearanceModel，通过构建者模式实现，setTopLeft表示处理左上角，其他同理。
        //cornerSize表示设置的大小，有RelativeCornerSize和AbsoluteCornerSize，RelativeCornerSize构造方法接收一个百分比，范围0-1；AbsoluteCornerSize构造方法接收一个具体数值，这个数值就是圆角的数值。
        //这里还有个CornerFamily，它表示处理的方式，有ROUNDED和CUT两种，ROUNDED是圆角，CUT是直接将圆角部分裁切掉。setAllCornerSizes(ShapeAppearanceModel.PILL)可以直接实现圆形效果。
        ShapeAppearanceModel build = ShapeAppearanceModel.builder()
                .setAllCorners(CornerFamily.ROUNDED, 20f)
                .setTopLeftCorner(CornerFamily.CUT, new RelativeCornerSize(0.3f))
                .setTopRightCorner(CornerFamily.CUT, new RelativeCornerSize(0.3f))
                .setBottomRightCorner(CornerFamily.CUT, new RelativeCornerSize(0.3f))
                .setBottomLeftCorner(CornerFamily.CUT, new RelativeCornerSize(0.3f))
                .setAllCornerSizes(ShapeAppearanceModel.PILL)
                .setTopLeftCornerSize(20f)
                .setTopRightCornerSize(new RelativeCornerSize(0.5f))
                .setBottomLeftCornerSize(10f)
                .setBottomRightCornerSize(new AbsoluteCornerSize(30f))
                .build();
        logo.setShapeAppearanceModel(build);
    }

    public void networkImg(View view) {
        String imgUrl = "http://img5.adesk.com/5f59ab8de7bce77595e55145?imageMogr2/thumbnail/!720x1280r/gravity/Center/crop/720x1280";
        Glide.with(this).load(imgUrl).into(logo);
    }
}